package com.zzyl.controller.security;

import com.zzyl.base.PageBean;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.UserDto;
import com.zzyl.service.UserService;
import com.zzyl.vo.UserVo;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(tags = "用户管理")
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserService userService;

    //TODO @ApiOperation("用户分页")
    @PostMapping("/page/{pageNum}/{pageSize}")
    public ResponseResult<PageBean<UserVo>> query(@RequestBody UserDto dto, @PathVariable("pageNum") int pageNum,
                                                  @PathVariable("pageSize") int pageSize) {
        PageBean<UserVo> vo = userService.query(dto, pageNum, pageSize);
        return ResponseResult.success(vo);
    }

    //TODO @ApiOperation("用户添加")
    @PutMapping
    public ResponseResult<Boolean> add(@RequestBody UserDto userDto) {
        userService.add(userDto);
        return ResponseResult.success(true);
    }

    //TODO @ApiOperation("用户修改")
    @PatchMapping
    public ResponseResult<Boolean> update(@RequestBody UserDto userDto) {
        userService.update(userDto);
        return ResponseResult.success(true);
    }

    //TODO @ApiOperation("删除用户")
    @DeleteMapping("/remove/{userIds}")
    public ResponseResult<Void> delete(@PathVariable Long userIds) {
        userService.delete(userIds);
        return ResponseResult.success();
    }

    //TODO @ApiOperation("启用或禁用用户")
    @PutMapping("/is-enable/{id}/{status}")
    public ResponseResult<Void> isenable(@PathVariable Long id, @PathVariable String status) {
        userService.isenable(id, status);
        return ResponseResult.success();
    }

    //TODO @ApiOperation("用户列表")
    @PostMapping("list")
    public ResponseResult<List<UserVo>> list(@RequestBody UserDto dto) {
        List<UserVo> vos = userService.list(dto);
        return ResponseResult.success(vos);
    }

    //TODO @ApiOperation("密码重置")
    @PostMapping("reset-password/{userId}")
    public ResponseResult<Void> password(@PathVariable Long userId) {
        userService.password(userId);
        return ResponseResult.success();
    }

    @GetMapping("/current-user")
    public ResponseResult<UserVo> user() {
        UserVo vo = userService.user();
        return ResponseResult.success(vo);

    }
}
